﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model CubicFWNet.Data.Models.Order
@{
    //var product = ViewBag.Product as Product;
    var customerShortName = ViewBag.CustomerShortName;
    var proList = ViewBag.ProList as IQueryable<ProductTechnologyView>;
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
    var generateNum = ViewBag.GenerateNum;
}
<section class="content-header">
    <h1>
        添加发货单
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("InvoiceQuery", "Order")">发货单查询</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("AddInvoice", "Order")" method="post">
                        <input type="hidden" id="OrderId" name="OrderId" value="@Model.Id" />
                        <div class="box-body">
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发货单号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Number" name="Number" value="@generateNum" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">填单日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" placeholder="" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">简称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="customerShortName" name="customerShortName" value="@customerShortName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">收货单位</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="TakeCompany" name="TakeCompany" value="" required>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发货日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control Timedatepicker" id="DliveryTime" name="DliveryTime" value="" required>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">预计到货日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control Timedatepicker" id="ReceivedTime" name="ReceivedTime" value="" required>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">收货人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ReceivePeople" name="ReceivePeople" value="" required>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发货人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SendPeople" name="SendPeople" value="" required>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">承运商</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="Carrier" name="Carrier" value="" required>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发货仓库</label>
                                <div class="col-sm-9">
                                    <select class="form-control" id="StoreType" name="StoreType">
                                        <option value="1">成品仓</option>
                                        <option value="2">原料仓</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">送货要求</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="DliveryDemand" id="DliveryDemand"></textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>

                            <div id="json-content" class="col-md-10 col-md-offset-1" >

                                @*<div class="form-group col-md-6">
                                        <label class="col-sm-3 control-label">数量</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control okeydown" data-des="数量" id="Amount" name="Amount" value="@tmView.Amount">
                                        </div>
                                    </div>*@
                                <table class="footable table table-stripped table-bordered table-hover" id="footable">
                                    <thead>
                                        <tr>
                                            <th data-sort-ignore="true">
                                                品名
                                            </th>
                                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                                尺寸宽-mm
                                            </th>
                                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                                尺寸长-mm
                                            </th>
                                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                                规格
                                            </th>
                                            <th data-hide="phone,tablet" data-sort-ignore="true">
                                                基本单位
                                            </th>
                                            <th data-hide="phone,tablet" data-sort-ignore="true" class="col-md-2">
                                                数量
                                            </th>
                                            <th data-hide="phone,tablet" data-sort-ignore="true" class="col-md-2">
                                                价格
                                            </th>
                                            <th data-hide="phone,tablet" data-sort-ignore="true" class="col-md-2">
                                                金额
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @if (proList != null)
                                        {
                                            foreach (var item in proList)
                                            {
                                                <tr class="tr">
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.ProductName)
                                                    </td>
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.SizeWidth)
                                                    </td>
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.SizeLenth)
                                                    </td>
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.Unit)
                                                    </td>
                                                    <td>
                                                        @Html.DisplayFor(modelItem => item.Pack)
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control okeydown itemAmount" data-itemprice="@item.Price" id="itemAmount" name="itemAmount" value="@item.Amount" required>
                                                        @*@Html.DisplayFor(modelItem => item.Amount)*@
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control okeydown itemPrice" id="itemPrice" name="itemPrice" value="@item.Price" readonly="readonly">
                                                        @*@Html.DisplayFor(modelItem => item.Price)*@
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control okeydown itemMoney" id="itemMoney" name="itemMoney" value="@item.TotalPrice.ToString("f2")" readonly="readonly">
                                                    </td>
                                                </tr>
                                            }
                                        }
                                    </tbody>
                                </table>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-12" style="height: 1px;">
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">添加</a>
                            <a class="btn btn-primary submitbtn" href="@Url.Action("ServiceItem", "Technology")">返回</a>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#footable').footable();

            //日期控件
            $(".Timedatepicker").datepicker({
                autoclose: true,
                language: 'zh', //汉化
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                minView: "month"//选择日期后，不会再跳转去选择时分秒
            });

            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    postData.Data = getParam();//JSON.stringify(postData._Data);
                    postData.Type = type;
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("ServiceItem", "Technology")';
                        }
                    });
                }
            });
        });

        var type = 1;
        function formsubmit(t) {
            type = t;
            $("#frmedit").submit();
        }


        $(".itemAmount").keyup(function () {
            var amount = $(this).val() / 1;
            var price = $(this).attr('data-itemprice');
            var b = (amount * price).toFixed(2);
            $(this).parents(".tr").find(".itemMoney").val(b);
        });


        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

        function getParam() {
            var postdata = [];
            //主键
            $("#json-content").find('input,select,textarea').each(function (r) {
                var $this = $(this);
                var id = $this.attr('id');
                var type = $this.attr('type');
                if (id) {
                    switch (type) {
                        case "checkbox":
                            postdata.push({ des: $this.attr("data-des"), name: id, value: $this.is(":checked") });
                            break;
                        case "select":
                            var value = $this.find("option:selected").val() == "" ? null : $this.find("option:selected").val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                        default:
                            var value = $this.val() == "" ? "&nbsp;" : $this.val();
                            postdata.push({ des: $this.attr("data-des"), name: id, value: value });
                            break;
                    }
                }
            });
            return JSON.stringify(postdata);
        }


    </script>
}